package com.ruoyi.forApp.service.imp;

import com.ruoyi.forApp.domain.CourseForApp;
import com.ruoyi.forApp.service.ICourseServiceForApp;
import com.ruoyi.project.system.course.domain.Course;
import com.ruoyi.project.system.course.domain.CourseArrange;
import com.ruoyi.project.system.course.domain.CourseClass;
import com.ruoyi.project.system.course.mapper.CourseClassMapper;
import com.ruoyi.project.system.course.service.ICourseArrangeService;
import com.ruoyi.project.system.course.service.ICourseService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CourseServiceForApp implements ICourseServiceForApp {

    @Autowired
    private CourseClassMapper courseClassMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private ICourseArrangeService courseArrangeService;

    @Override
    public List<CourseForApp> getCourseList(Long userId) {
        User user=userMapper.selectUserById(userId);
        List<CourseForApp> courseForApps=new ArrayList<>();
        CourseArrange courseArrange=new CourseArrange();
        courseArrange.setDeptId(user.getDeptId());
        List<CourseArrange> courseArranges=courseArrangeService.selectCourseArrangeList(courseArrange);
        for (CourseArrange courseArrange1:courseArranges){
            if (courseArrange1.getTeacherId()==null){
                continue;
            }
            Course course=courseService.selectCourseById(courseArrange1.getCourseId());
            CourseForApp courseForApp=new CourseForApp();
            courseForApp.setCourseId(course.getCourseId());
            courseForApp.setCourseName(course.getCourseName());
            courseForApps.add(courseForApp);
        }
        return courseForApps;
    }
}
